package 多态;

class Animal{
    public String nane;
    public int age;

    public Animal(String nane, int age) {
        this.nane = nane;
        this.age = age;
    }

    public String getNane() {
        return nane;
    }

    public void setNane(String nane) {
        this.nane = nane;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void  eat(){
        System.out.println(getNane()+"正在吃饭");
    }
    @Override
    public String toString() {
        return "Animal{" +
                "nane='" + nane + '\'' +
                ", age=" + age +
                '}';
    }

}

class Dog extends Animal{

    public Dog(String nane, int age) {
        super(nane, age);
    }

    public void eat(){
        System.out.println(getNane()+"正在吃狗粮");
    }

}
class  Bird extends Animal{

    public Bird(String nane, int age) {
        super(nane, age);
    }
    public void fly(){
        System.out.println(getNane()+"飞");
    }

    public void eat(){
        System.out.println(getNane()+"吃鸟粮");
    }
}
public class Test {
    public  void func(Animal animal){//重写: 子类和夫类方法 参数列表 返回值 都一样.
        animal.eat();//多态
        //动态绑定(编译时用的是父类的eat运行时用的是子类的eat）//子类和夫类都拥有这个方法时（重写）
    }
    public static void main(String[] args) {
//        Bird bird=new Bird("鹦鹉",1);
//        Animal animal=bird;
//        //夫类引用引用子类的对象
        Test test =new Test();

        test.func(new Bird("鹦鹉",1));

        test.func(new Dog("田园犬",2));


    }
}
